package service.examinfo;

import java.util.List;

import config.PageConfig;
import util.manager.PageManager;
import util.paramvo.MemberPageListParamVO;
import util.paramvo.UnitPageListParamVO;
import util.returnvo.ExaminfoListReturnVO;
import vo.ExaminfoVO;
import dao.examinfo.ExaminfoDAO;

public class ExaminfoServiceImpl implements ExaminfoService{

	private ExaminfoDAO examinfoDAO;

	public void setExaminfoDAO(ExaminfoDAO examinfoDAO) {
		this.examinfoDAO = examinfoDAO;
	}

	@Override
	public ExaminfoListReturnVO getExaminfos(int majorunit_no, String page)	throws Exception {
		int pageNo=1;
		if(page!=null && !page.equals("")) pageNo=Integer.parseInt(page);
		List<ExaminfoVO> eList=examinfoDAO.getExaminfos(new UnitPageListParamVO(majorunit_no, PageConfig.EXAMINFO_ROW_PER_PAGE, pageNo));
		PageManager pageManager=new PageManager(PageConfig.EXAMINFO_ROW_PER_PAGE, PageConfig.EXAMINFO_PAGE_PER_GROUP, examinfoDAO.getExaminfoCount(majorunit_no), pageNo);
		return new ExaminfoListReturnVO(eList, pageManager);
	}

	@Override
	public void registerExaminfo(ExaminfoVO param) throws Exception {
		examinfoDAO.registerExaminfo(param);
	}

	@Override
	public void updateExaminfo(ExaminfoVO param) throws Exception {
		examinfoDAO.updateExaminfo(param);
	}

	@Override
	public void deleteExaminfo(int examinfo_no) throws Exception {
		examinfoDAO.deleteExaminfo(examinfo_no);
	}
	
	@Override
	public int didWriteExaminfo(ExaminfoVO param) throws Exception {
		return examinfoDAO.didWriteExaminfo(param);
	}

	@Override
	public ExaminfoListReturnVO getMyExaminfos(int member_no, String page) throws Exception {
		int pageNo=1;
		if(page!=null && !page.equals("")) pageNo=Integer.parseInt(page);
		
		List<ExaminfoVO> eList=examinfoDAO.getMyExaminfos(new MemberPageListParamVO(member_no, PageConfig.EXAMINFO_ROW_PER_PAGE, pageNo));
		PageManager pageManager=new PageManager(PageConfig.EXAMINFO_ROW_PER_PAGE, PageConfig.EXAMINFO_PAGE_PER_GROUP, examinfoDAO.getMyExaminfoCount(member_no), pageNo);
		return new ExaminfoListReturnVO(eList, pageManager);
	}
}
